﻿@using lsc.Model
@model lsc.Model.SendEmailTask

@{
    ViewData["Title"] = "添加邮件发送任务";
    Layout = "~/Pages/_Layout.cshtml";
    List<EmailTemplate> list = ViewBag.list;
}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加邮件发送任务</legend>
</fieldset>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-md6">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">邮件模板</label>
                    <div class="layui-input-block">
                        <select name="EmailTempId" lay-verify="required" lay-search>
                            <option value="" ></option>
                            @if (list!=null)
                            {
                                foreach (EmailTemplate emailTemplate in list)
                                {
                                    <option value="@(emailTemplate.Id)"  @(emailTemplate.Id==ViewBag.emailtempId?"selected":"")>@(emailTemplate.Title)</option>
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">任务名称</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="TaskName" required  lay-verify="required" placeholder="请输入任务名称" autocomplete="off" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">目标邮箱</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="Email"  placeholder="请输入目标邮箱" autocomplete="off" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否对所有目标邮箱发送</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="sendAll" lay-skin="switch">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="*">提交任务并开始发送</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@section Scripts{
    <script type="text/javascript">
        var layer;
        layui.use(['form', 'layer','element'], function () {
            var form = layui.form;
            var element = layui.element;
            layer = layer;

            form.on('submit(*)', function (data) {

                $.post('/EmailManage/SaveSendEmailTask',
                    data.field,
                    function(res) {
                        if (res.code == 1) {
                            layer.msg('邮件已经开始发送', { icon: 6 });
                            window.location = '/EmailManage/SendEmailTaskList';
                        } else {
                            layer.msg('任务保存失败', { icon: 5 });
                        }
                    });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });

    </script>
}